//import axios from 'axios';

// axios.get('http://192.168.11.1:1448/api/core/slam/v1/maps/explore', {
// responseType: 'arraybuffer'
// })
// .then(response => {
//    // console.log(response,'dedede')
//     // response.data 即为二进制数据
//     console.log(
//         response.data.slice(0, 4),
//         new Float32Array(response.data.slice(0, 4))[0],
//         new Float32Array(response.data.slice(4, 8))[0],
//         new Uint32Array(response.data.slice(8, 12))[0],
//         new Uint32Array(response.data.slice(12, 16))[0],
//         new Float32Array(response.data.slice(16, 20))[0]
// )
//    // ,'response'); // 新内存
//   //let view = new DataView(response.data);
//    //console.log(arrayBufferToString(response.data),'y8yhugi---')

// });
// function arrayBufferToString(buffer, encoding = 'utf-8') {
//     const decoder = new TextDecoder(encoding);
//     return decoder.decode(buffer);
//   }

// function Uint8ArrayToString(fileData){
//   var dataString = "";
//   for (var i = 0; i < fileData.length; i++) {
//     dataString += String.fromCharCode(fileData[i]);
//   }
 
//   return dataString

// }

export function isArray(val: any) {
    return Object.prototype.toString.call(val) === "[object Array]";
}

export function isEmpty(val: any) {
    return (
        val === undefined ||
        val === null ||
        (typeof val === "string" && val.length === 0) ||
        (isArray(val) && val.length === 0) ||
        (typeof val === "number" && isNaN(val))
    );
}

export function isDate(val: any) {
    return Object.prototype.toString.call(val) === "[object Date]";
}

export function isNumber(val: any) {
    return Object.prototype.toString.call(val) === "[object Number]";
}

export function parseTime(time:any, cFormat?:string) {
    if (arguments.length === 0) {
        return null;
    }

    const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
    let date;
    if (isDate(time)) {
        date = time;
    } else if (isNumber(time)) {
        if (String(time).length === 10) time = parseInt(time) * 1000;
        date = new Date(time);
    } else {
        date = new Date(time);
    }

    const formatObj:any = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds(),
        a: date.getDay()
    };

    //console.log(formatObj,'formatObj')

    const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
        let value = formatObj[key];
        if (key === "a")
            return ["日","一", "二", "三", "四", "五", "六"][value];
        if (result.length > 0 && value < 10) {
            value = "0" + value;
        }
        return value || 0;
    });

    return time_str;
}

export function handlePicGroups(picList:any){
    const groups: any = []
    for (let i = 0; i < picList.length; ) {
      const group = picList.slice(i, (i += 4))
      //groups.push(group)
      if (group.length === 4) {
        groups.push(group)
      }
    }
    return groups
}

export function debounce(func:any, wait: number, immediate: boolean) {
    let timeout:any, args:any, context:any, timestamp:any, result:any;
   // console.log(this,"234343njnjnk")
    const later = function() {
        // 据上一次触发时间间隔
        const last = +new Date() - timestamp;
        // 上次被包装函数被调用时间间隔last小于设定时间间隔wait
        if (last < wait && last > 0) {
            timeout = setTimeout(later, wait - last);
        } else {
            timeout = null;
            // 如果设定为immediate===true，因为开始边界已经调用过了此处无需调用
            if (!immediate) {
                result = func.apply(context, args);
                if (!timeout) context = args = null;
            }
        }
    };

    return function(...args1:any) {
        context = this;
        timestamp = +new Date();
        const callNow = immediate && !timeout;
        // 如果延时不存在，重新设定延时
        args = args1;
        if (!timeout) timeout = setTimeout(later, wait);
        if (callNow) {
            result = func.apply(context, args);
            context = args = null;
        }

        return result;
    };
}

export function objectCopy(obj){
    return JSON.parse(JSON.stringify(obj))
}

/** * 是否为mac系统（包含iphone手机） * */ 
export function isMac() { 
    return /macintosh|mac os x/i.test(navigator.userAgent);
};

 /** * 是否为windows系统 * */
export function isWindows() { 
    return /windows|win32/i.test(navigator.userAgent);
}; 

